

****************************************************************************************************************
****************************************************************************************************************
********** TABLE  7				  ******************************************************************************
****************************************************************************************************************
****************************************************************************************************************


set more off
use  "${data}Panel_quarterly.dta", replace

* Sample: We restrict the sample to the periods T and T-4 for UI recipients and remove singletons :

rename UI I_UI
keep if analysis_sample==1
bys spell_identifier: egen min_quarter_to_exhaustion=min(quarter_to_exhaustion) 	if I_UI==1
keep if ( quarter_to_exhaustion==0 | quarter_to_exhaustion==4 | I_UI==0) & (min_quarter_to_exhaustion<0 | I_UI==0)

* We get individual covariates:

merge n:1 spell_identifier using  "${data}Cross_section.dta"
keep if _merge==3
drop _merge

* We create interactions individual covariates*T :

foreach var in  woman_kid man_nokid man_kid  age_2 age_3  age_4 age_5 educ_high educ_middle  qualif_med qualif_high  ///
ind_full_time ind_blue_low_skill ind_blue_skill ind_exp_1 ind_exp_2 ind_exp_3 ind_exp_4 ind_exp_5 ln_ref_wage_hourly ///
past_duration_0 past_duration_1 past_duration_2 past_duration_3 ln_benefit_monthly    ind_cum_duration  jobloss{
gen b_`var'=0
replace b_`var'=`var' if I_UI==1 & quarter_to_exhaustion!=4
forvalue i=1/13{
cap drop quarter_`i'_`var'
gen quarter_`i'_`var' = 0
replace quarter_`i'_`var' = `var' if  quarter_`i'==1
}
}

 
* Label:

global Interaction_b " b_man_nokid b_woman_kid b_man_kid  b_age_2 b_age_3 b_age_4 b_age_5 b_educ_middle b_educ_high  b_qualif_med  b_qualif_high  b_ind_full_time    b_ind_exp_2 b_ind_exp_3 b_ind_exp_4 b_ind_exp_5 b_past_duration_1 b_past_duration_2 b_past_duration_3  b_jobloss   "
label var b_ln_benefit_monthly "UI level (log) $*T$"
label var b_man_nokid "Man, no kid $* T$"
label var b_woman_kid "Woman, no kid $* T$"
label var b_man_kid "Man, kid $* T$"
label var b_age_2 "Age: 25-35 $* T$"
label var b_age_3 "Age: 35-45 $* T$"
label var b_age_4 "Age: 45-55 $* T$"
label var b_age_5 "Age: $>55 * T$ "
label var b_educ_middle "Education level: intermediate *T"
label var b_educ_high  "Education level: high *T"
label var b_qualif_med  "Qualification level: intermediate $* T$"
label var b_qualif_high  "Qualification level: high $* T$"
label var b_ind_full_time    "Full time $* T$"
label var b_ind_exp_2 "Experience: 1 year $* T$"
label var b_ind_exp_3 "Experience: 2 year $* T$"
label var b_ind_exp_4 "Experience: 3-5 year $* T$"
label var b_ind_exp_5 "Experience: $>5$ year $* T$"
label var b_past_duration_1 "Past U: 1 year $* T$"
label var b_past_duration_2 "Past U: 2 year $* T$"
label var b_past_duration_3	"Past U: $>2$ year $* T$"
label var b_jobloss	"Lost job just before$* T$" 

set more off
global var "Count_Application"
xi : xtpoisson ${var} quarter_to_exhaustion_0 b_ln_benefit_monthly ${SpellTimeFE}   		,   fe vce(robust)
est store est01
xi : xtpoisson ${var} quarter_to_exhaustion_0 b_ln_benefit_monthly ${Interaction_b} ${SpellTimeFE}   		,   fe vce(robust)
est store est02
xi : xtpoisson ${var} quarter_to_exhaustion_0 b_ln_benefit_monthly b_ln_ref_wage_hourly ${Interaction_b}  ${SpellTimeFE}   ,   fe vce(robust)
est store est03
global var "ln_explained_monthly_w"
xi : reghdfe  ${var} quarter_to_exhaustion_0 b_ln_benefit_monthly	${SpellTimeFE} ,   	absorb(spell_identifier) cluster(spell_identifier)
est store est04
xi : reghdfe  ${var} quarter_to_exhaustion_0 b_ln_benefit_monthly ${Interaction_b}	${SpellTimeFE} ,   	absorb(spell_identifier) cluster(spell_identifier)
est store est05
xi : reghdfe  ${var} quarter_to_exhaustion_0 b_ln_benefit_monthly b_ln_ref_wage_hourly ${Interaction_b}	${SpellTimeFE} ,   	absorb(spell_identifier) cluster(spell_identifier)
est store est06


******* Latex Table:

estout est01 est02 est03 est04 est05 est06  using "${path}Table7",  ///
keep (b_* ) stats(N, labels( "No. of Obs") fmt( %9.0fc )) style(tex) cells( b(star fmt(3)) se(par fmt(3)) )   starlevels( * 0.10 ** 0.05 *** 0.010) ///
mgroups("Search effort" "Targeted monthly wage", pattern(1 0 0 1 0 0)  prefix(\multicolumn{@span}{c}{) suffix(})   span erepeat(\cmidrule(lr){@span})) ///
 title(" Heterogeneous reaction to benefits exhaustion")   label legend  replace numbers mlabels(none)   collabels(none) 

******* Excel Table:

label var b_ln_benefit_monthly "UI level (log) *T"
label var b_man_nokid "Man, no kid *T"
label var b_woman_kid "Woman, no kid *T"
label var b_man_kid "Man, kid *T"
label var b_age_2 "Age: 25-35 *T"
label var b_age_3 "Age: 35-45 *T"
label var b_age_4 "Age: 45-55 *T"
label var b_age_5 "Age:  >55 * T  "
label var b_educ_middle "Education level: intermediate *T"
label var b_educ_high  "Education level: high *T"
label var b_qualif_med  "Qualification level: intermediate *T"
label var b_qualif_high  "Qualification level: high *T"
label var b_ind_full_time    "Full time *T"
label var b_ind_exp_2 "Experience: 1 year *T"
label var b_ind_exp_3 "Experience: 2 year *T"
label var b_ind_exp_4 "Experience: 3-5 year *T"
label var b_ind_exp_5 "Experience:  >5  year *T"
label var b_past_duration_1 "Past U: 1 year *T"
label var b_past_duration_2 "Past U: 2 year *T"
label var b_past_duration_3	"Past U:  >2  year *T"
label var b_jobloss	"Lost job just before*T" 

  
estout est01 est02 est03 est04 est05 est06   using "${path}Table7.xls",  ///
keep (b_* ) stats(N, labels( "No. of Obs") fmt( %9.0fc ))  cells( b(star fmt(3)) se(fmt(3)) )   starlevels( * 0.10 ** 0.05 *** 0.010) ///
mgroups("Search effort" "Targeted monthly wage", pattern(1 0 0 1 0 0)  ) ///
 title(" Heterogeneous reaction to benefits exhaustion")   label legend  replace  mlabels("1" "2" "3" "4" "5" "6")    collabels(none) 


